home *** CD-ROM | disk | FTP | other *** search
/ Champak 106 / Vol 106.iso / games / global_r.swf / scripts / __Packages / Cannon.as < prev    next >
Encoding:
Text File  |  2010-04-12  |  6.0 KB  |  160 lines

  1. class Cannon
  2. {
  3.    var index;
  4.    var bmpBase;
  5.    var bmpBarrel;
  6.    var bmpExplode;
  7.    var bmpCanvas;
  8.    var position;
  9.    var VEL;
  10.    var energy;
  11.    var frameExp;
  12.    var shotDelay;
  13.    var bOnScreen;
  14.    var bFlash;
  15.    var rotation;
  16.    var screenPos;
  17.    var maxRot = 2.6179938779914944;
  18.    var minRot = 0.5235987755982988;
  19.    function Cannon(pos, type, indexNew)
  20.    {
  21.       this.index = indexNew;
  22.       var _loc2_ = flash.display.BitmapData.loadBitmap("gunTank");
  23.       this.bmpBase = new flash.display.BitmapData(77,56,true,0);
  24.       this.bmpBase.copyPixels(_loc2_,new flash.geom.Rectangle(0,type * 56,77,56),new flash.geom.Point(0,0),null,null,true);
  25.       _loc2_ = flash.display.BitmapData.loadBitmap("gunTankGun");
  26.       this.bmpBarrel = new flash.display.BitmapData(39,24,true,0);
  27.       this.bmpBarrel.copyPixels(_loc2_,new flash.geom.Rectangle(0,type * 24,39,24),new flash.geom.Point(0,0),null,null,true);
  28.       this.bmpExplode = flash.display.BitmapData.loadBitmap("explosion0");
  29.       this.bmpCanvas = Game.bmpDead;
  30.       this.position = pos.clone();
  31.       this.VEL = 10;
  32.       this.energy = 5;
  33.       this.frameExp = 0;
  34.       this.shotDelay = 1;
  35.       this.bOnScreen = false;
  36.       this.bFlash = false;
  37.    }
  38.    function getPosition(Void)
  39.    {
  40.       return this.position.clone();
  41.    }
  42.    function step(chopperPos, chopperVel, aShots)
  43.    {
  44.       if(!this.bOnScreen || this.energy == 0)
  45.       {
  46.          return undefined;
  47.       }
  48.       var _loc4_ = aShots.length;
  49.       var _loc3_ = 0;
  50.       while(_loc3_ < _loc4_)
  51.       {
  52.          var _loc2_ = Shot(aShots[_loc3_]);
  53.          var _loc7_ = _loc2_.position.x - this.position.x;
  54.          var _loc6_ = _loc2_.position.y - (this.position.y - 2);
  55.          if(_loc7_ * _loc7_ + _loc6_ * _loc6_ < 1600)
  56.          {
  57.             Game.getInstance().removeAllyShot(_loc2_);
  58.             this.energy = this.energy - 1;
  59.             this.bFlash = true;
  60.             Game.getInstance().createShrapnel(_loc2_.position);
  61.             if(this.energy == 0)
  62.             {
  63.                Game.getInstance().saveHostileInd(this.index);
  64.                Game.getInstance().addPoints(this.position,200);
  65.                Sounds.playSound("bazooka");
  66.                trace("destroyed");
  67.             }
  68.             break;
  69.          }
  70.          _loc3_ = _loc3_ + 1;
  71.       }
  72.       _loc7_ = chopperPos.x + chopperVel.x * 10 - this.position.x;
  73.       _loc6_ = chopperPos.y + chopperVel.y * 10 - this.position.y;
  74.       this.rotation = Math.atan2(_loc6_,_loc7_);
  75.       if(this.rotation > this.maxRot)
  76.       {
  77.          this.rotation = this.maxRot;
  78.       }
  79.       else if(this.rotation < this.minRot)
  80.       {
  81.          this.rotation = this.minRot;
  82.       }
  83.       if(this.shotDelay-- <= 0)
  84.       {
  85.          this.shotDelay = 40 + Math.round(30 * Math.random());
  86.          var _loc10_ = new flash.geom.Point(this.position.x - 24 + 30 * Math.cos(this.rotation),this.position.y + 52 + 30 * Math.sin(this.rotation));
  87.          var _loc9_ = this.rotation + 3.141592653589793 * Math.round(15 * (1 - 2 * Math.random())) / 180;
  88.          var _loc11_ = new flash.geom.Point(this.VEL * Math.cos(_loc9_),this.VEL * Math.sin(_loc9_));
  89.          var _loc8_ = 20 + Math.round(15 * Math.random());
  90.          _loc8_ = 5 + Math.round(Math.sqrt(_loc7_ * _loc7_ + _loc6_ * _loc6_) / this.VEL) + Math.round(15 * (1 - 2 * Math.random()));
  91.          Game.getInstance().createShot(false,_loc10_,_loc11_,_loc8_);
  92.          Sounds.playSound("gunfire");
  93.       }
  94.    }
  95.    function draw(leftEdge)
  96.    {
  97.       var _loc8_ = this.position.x - leftEdge - this.bmpBase.width / 2;
  98.       var _loc7_ = this.position.y + this.bmpBase.height / 2;
  99.       this.screenPos = new flash.geom.Point(_loc8_,_loc7_);
  100.       if(_loc8_ > (- this.bmpBase.width) * 1 && _loc8_ < Game.screenW)
  101.       {
  102.          this.bOnScreen = true;
  103.          if(this.energy > 0)
  104.          {
  105.             var _loc2_ = new flash.display.BitmapData(this.bmpBarrel.width,this.bmpBarrel.height,true,0);
  106.             _loc2_.copyPixels(this.bmpBarrel,this.bmpBarrel.rectangle,new flash.geom.Point(0,0),null,null,true);
  107.             var _loc3_ = new flash.geom.Matrix();
  108.             _loc3_.translate((- _loc2_.width) / 2,(- _loc2_.height) / 2);
  109.             var _loc6_ = new flash.geom.Matrix();
  110.             _loc6_.rotate(- this.rotation);
  111.             _loc3_.concat(_loc6_);
  112.             var _loc5_ = new flash.geom.Matrix();
  113.             _loc5_.translate(_loc8_ + 14,Game.screenH - (_loc7_ - 4));
  114.             _loc3_.concat(_loc5_);
  115.             var _loc9_ = !this.bFlash ? null : new flash.geom.ColorTransform(0,0,0,0,255,255,255,255);
  116.             this.bmpCanvas.draw(_loc2_,_loc3_,_loc9_,null,null,true);
  117.             var _loc4_ = this.bmpBase.clone();
  118.             if(this.bFlash)
  119.             {
  120.                _loc4_.colorTransform(_loc4_.rectangle,new flash.geom.ColorTransform(0,0,0,0,255,255,255,255));
  121.             }
  122.             this.bmpCanvas.copyPixels(_loc4_,_loc4_.rectangle,new flash.geom.Point(this.screenPos.x,Game.screenH - this.screenPos.y),null,null,true);
  123.             this.bFlash = false;
  124.          }
  125.          else
  126.          {
  127.             _loc8_ = this.position.x - leftEdge;
  128.             _loc7_ = this.position.y;
  129.             this.screenPos = new flash.geom.Point(_loc8_,_loc7_);
  130.             this.drawExplosion(this.screenPos,true);
  131.          }
  132.       }
  133.       else
  134.       {
  135.          this.bOnScreen = false;
  136.       }
  137.    }
  138.    function drawExplosion(pos, bRemove)
  139.    {
  140.       var _loc3_ = _root.attachMovie("explosion2","mcExp",_root.getNextHighestDepth());
  141.       _loc3_.gotoAndStop(this.frameExp + 1);
  142.       var _loc4_ = new flash.geom.Matrix();
  143.       _loc4_.translate(pos.x,Game.screenH - pos.y);
  144.       this.bmpCanvas.draw(_loc3_,_loc4_,null,null,null,true);
  145.       _loc3_.removeMovieClip();
  146.       this.frameExp = this.frameExp + 1;
  147.       if(this.frameExp == 27)
  148.       {
  149.          if(bRemove)
  150.          {
  151.             this.onEndDeadAnim();
  152.          }
  153.       }
  154.    }
  155.    function onEndDeadAnim(Void)
  156.    {
  157.       Game.getInstance().removeHostile(this);
  158.    }
  159. }
  160.